﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:mainmenu="clr-namespace:Peter.Common.MainMenu;assembly=Peter.Common"
                    xmlns:icons="clr-namespace:Peter.Common.Icons;assembly=Peter.Common"
                    xmlns:controls="clr-namespace:Peter.Common.Controls;assembly=Peter.Common"
                    xmlns:utilities="clr-namespace:Peter.Common.Utilities;assembly=Peter.Common"
                    xmlns:bindingConverters="clr-namespace:Peter.Common.BindingConverters;assembly=Peter.Common">

   <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="Default.Light.Colors.xaml" />
   </ResourceDictionary.MergedDictionaries>

   <BooleanToVisibilityConverter x:Key="BoolToVisi" />
   <bindingConverters:IconDisplayConverter x:Key="IconDisplay" />
   <mainmenu:MainMenuMenuItemStyleSelector x:Key="MenuItemStyleSelector" />
   <SolidColorBrush x:Key="BaseBackground"
                    Color="#D8D8D9" />
   <SolidColorBrush x:Key="HighlightBackground"
                    Color="#EBEBEB" />
   <SolidColorBrush x:Key="FocusedBackground"
                    Color="#FFFFFF" />
   <SolidColorBrush x:Key="SelectedBackground"
                    Color="#32373B" />

   <SolidColorBrush x:Key="DisabledForeground"
                    Color="#AAAAAA" />

   <ControlTemplate TargetType="Button"
                    x:Key="MainMenuButtonTemplate">
      <Border x:Name="PART_Border"
              BorderThickness="0">
         <ContentPresenter Content="{TemplateBinding Content}" />
      </Border>

      <ControlTemplate.Triggers>
         <Trigger Property="IsMouseOver"
                  Value="True">
            <Setter TargetName="PART_Border"
                    Property="Background"
                    Value="{StaticResource HighlightBackground}" />
            <Setter Property="Foreground"
                    Value="Black"/>
         </Trigger>

         <MultiTrigger>
            <MultiTrigger.Conditions>
               <Condition Property="IsMouseOver"
                          Value="True" />
               <Condition Property="IsFocused"
                          Value="True" />
            </MultiTrigger.Conditions>
            <MultiTrigger.Setters>
               <Setter TargetName="PART_Border"
                       Property="Background"
                       Value="{StaticResource FocusedBackground}" />
            </MultiTrigger.Setters>
         </MultiTrigger>

         <Trigger Property="IsEnabled"
                  Value="False">
            <Setter Property="Foreground"
                    Value="{StaticResource DisabledText}" />
         </Trigger>
      </ControlTemplate.Triggers>
   </ControlTemplate>

   <Style x:Key="MainMenuTextBoxStyle">
      <Setter Property="Control.Template">
         <Setter.Value>
            <ControlTemplate TargetType="mainmenu:MainMenuItem">
               <StackPanel Orientation="Horizontal">
                  <icons:IconDisplay Icon="{Binding Path=Icon}"
                                     x:Name="_iconDisplay"
                                     Margin="0,0,4,0"
                                     IconSize="Medium" />
                  <controls:CommandTextBox Text="{Binding Path=Text, UpdateSourceTrigger=PropertyChanged}"
                                           KeyPressCommand="{Binding Path=KeyCommand}"
                                           PlaceHolderText="{Binding Path=Title}"
                                           Command="{Binding Path=Command}"
                                           Width="{Binding Path=Width}"
                                           CaretPosition="{Binding Path=CaretPosition}"
                                           utilities:FocusExtension.IsFocused="{Binding Path=IsFocused}"
                                           utilities:FocusExtension.FocusEvents="{Binding Path=FocusCommand}"
                                           VerticalAlignment="Center"
                                           VerticalContentAlignment="Center"
                                           CommandParameter="{Binding Path=CommandParameter}" />
               </StackPanel>
               <ControlTemplate.Triggers>
                  <DataTrigger Binding="{Binding Path=Icon}"
                               Value="None">
                     <Setter TargetName="_iconDisplay"
                             Property="Visibility"
                             Value="Collapsed" />
                  </DataTrigger>
               </ControlTemplate.Triggers>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <Style x:Key="MainMenuDropDownItemStyle"
          TargetType="{x:Type MenuItem}">
      <Setter Property="ToolTip"
              Value="{Binding Path=ToolTip}" />
      <Setter Property="Command"
              Value="{Binding Path=Command}" />
      <Setter Property="CommandParameter"
              Value="{Binding Path=CommandParameter}" />
      <Setter Property="ItemsSource"
              Value="{Binding Path=Children}" />
      <Setter Property="Header"
              Value="{Binding Path=Title}" />
      <Setter Property="Visibility"
              Value="{Binding Path=IsVisible, Converter={StaticResource BoolToVisi}}" />
      <Setter Property="Icon"
              Value="{Binding Path=Icon, Converter={StaticResource IconDisplay}}" />
      <Setter Property="ItemContainerStyleSelector"
              Value="{StaticResource MenuItemStyleSelector}" />
   </Style>

   <Style x:Key="MainMenuItemQaStyle">
      <Setter Property="Control.Template"
              Value="{StaticResource MainMenuButtonTemplate}" />
   </Style>

   <Style x:Key="MainMenuItemButtonStyle">
      <Setter Property="Control.Template"
              Value="{StaticResource MainMenuButtonTemplate}" />
      <Setter Property="Control.Foreground"
              Value="White" />
   </Style>

   <Style x:Key="MainMenuItemDropDownStyle">
      <Setter Property="Control.Foreground"
              Value="White" />
      <Setter Property="Control.Template">
         <Setter.Value>
            <ControlTemplate TargetType="Button">

               <Border x:Name="PART_Border">
                  <Grid>
                     <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                     </Grid.ColumnDefinitions>
                     <Border Grid.Column="0"
                             BorderBrush="White"
                             Margin="0,6"
                             x:Name="DropDownSeparator"
                             BorderThickness="{TemplateBinding BorderThickness}" />
                     <icons:IconDisplay Icon="ChevronDown"
                                        Grid.Column="1"
                                        Padding="4,0" />
                  </Grid>
               </Border>

               <ControlTemplate.Triggers>
                  <Trigger Property="IsMouseOver"
                           Value="True">
                     <Setter TargetName="PART_Border"
                             Property="Background"
                             Value="{StaticResource HighlightBackground}" />
                     <Setter TargetName="DropDownSeparator"
                             Property="BorderBrush"
                             Value="Black" />
                     <Setter Property="Foreground"
                             Value="Black" />
                  </Trigger>

                  <MultiTrigger>
                     <MultiTrigger.Conditions>
                        <Condition Property="IsMouseOver"
                                   Value="True" />
                        <Condition Property="IsFocused"
                                   Value="True" />
                     </MultiTrigger.Conditions>
                     <MultiTrigger.Setters>
                        <Setter TargetName="PART_Border"
                                Property="Background"
                                Value="{StaticResource FocusedBackground}" />
                     </MultiTrigger.Setters>
                  </MultiTrigger>

                  <Trigger Property="IsEnabled"
                           Value="False">
                     <Setter Property="Foreground"
                             Value="{StaticResource DisabledForeground}" />
                  </Trigger>
               </ControlTemplate.Triggers>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <Style x:Key="MainMenuContentAreaStyle">
      <Setter Property="Control.Margin"
              Value="0" />
      <Setter Property="Control.Background"
              Value="{StaticResource SelectedBackground}" />
   </Style>

   <Style TargetType="{x:Type mainmenu:MainMenuHeader}">
      <Setter Property="IsSelected"
              Value="{Binding Path=IsSelected}" />
      <Setter Property="IsEnabled"
              Value="{Binding Path=IsEnabled}" />
      <Setter Property="ToolTip"
              Value="{Binding Path=ToolTip}" />
      <Setter Property="Visibility"
              Value="{Binding Path=IsVisible, Converter={StaticResource BoolToVisi}}" />
      <Setter Property="IsTabStop"
              Value="False" />

      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type mainmenu:MainMenuHeader}">
               <Border BorderThickness="0"
                       Focusable="False"
                       Margin="0"
                       Height="33"
                       Padding="7,0"
                       x:Name="PART_Border">
                  <Grid>
                     <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                     </Grid.ColumnDefinitions>

                     <icons:IconDisplay HorizontalAlignment="Center"
                                        VerticalAlignment="Center"
                                        IconSize="{Binding Path=HeaderIconSize, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mainmenu:MainMenu}}}"
                                        x:Name="PART_Icon"
                                        Grid.Column="0"
                                        Icon="{Binding Path=Icon}" />

                     <TextBlock Grid.Column="1"
                                Focusable="False"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Name="PART_Title"
                                Margin="5,0"
                                FontSize="12"
                                TextTrimming="CharacterEllipsis"
                                Text="{Binding Path=Title}" />

                     <Button x:Name="PART_DropDown"
                             Grid.Column="2"
                             BorderThickness="0"
                             VerticalContentAlignment="Center"
                             HorizontalContentAlignment="Center"
                             Style="{DynamicResource MainMenuItemDropDownStyle}">
                        <Button.ContextMenu>
                           <ContextMenu ItemsSource="{Binding Path=MenuItems}"
                                        ItemContainerStyleSelector="{StaticResource MenuItemStyleSelector}" />
                        </Button.ContextMenu>
                     </Button>
                  </Grid>
               </Border>
               <ControlTemplate.Triggers>

                  <DataTrigger Binding="{Binding Path=IsSelected}"
                               Value="True">
                     <Setter TargetName="PART_Border"
                             Property="Background"
                             Value="{StaticResource SelectedBackground}" />
                     <Setter TargetName="PART_Title"
                             Property="FontWeight"
                             Value="Bold" />
                     <Setter Property="Foreground"
                             Value="White" />
                  </DataTrigger>

                  <DataTrigger Binding="{Binding Path=MenuItems}"
                               Value="{x:Null}">
                     <Setter TargetName="PART_DropDown"
                             Property="Visibility"
                             Value="Collapsed" />
                  </DataTrigger>

                  <DataTrigger Binding="{Binding Path=MenuItems.Count}"
                               Value="0">
                     <Setter TargetName="PART_DropDown"
                             Property="Visibility"
                             Value="Collapsed" />
                  </DataTrigger>

               </ControlTemplate.Triggers>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>


</ResourceDictionary>